
package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelContent;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    ITravelService travelService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelQuery qo, Model model){
        //待发布
        qo.setState(Travel.STATE_WAIT);
        //公开
        qo.setIsPublic(true);
        //创建时间正序
        qo.setOrderBy("t.createTime asc");
        model.addAttribute("pageInfo",travelService.query(qo));
        return "travel/list";
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public TravelContent getContentById(Long id){
       return travelService.getContentById(id);
    }

    @RequestMapping("changeState")
    @ResponseBody
    public JSONResult changeState(Travel travel){
        travelService.changeState(travel);
        return new JSONResult();
    }

    /**
     * 查询所有游记(游记绑定攻略)
     * @return
     */
    @RequestMapping("selectRelease")
    @ResponseBody
    public List selectRelease(){
        List<Travel> travels=travelService.selectAll();
        return travels;
    }
}
